package implementor;



import utility.AppUtilities;
import model.IssueSlipItem;
import dao.IssueSlipDao;
import dao.IssueSlipItemDao;
import dbhandelling.Crude;
import dto.IssueSlip;

public class IssueSlipImplementor extends Crude implements IssueSlipDao
{
	String className=new IssueSlip().getClass().getName();
	
	@Override
	public void add(IssueSlip issueSlip) throws Exception 
	{
		insert(issueSlip);
	}

	@Override
	public void update(IssueSlip issueSlip) throws Exception 
	{
		super.update(className,"status" ,issueSlip.getStatus()+"", "issueSlipNo",issueSlip.getIssueNo()+"");
	}

	@Override
	public void delete(IssueSlip issueSlip) throws Exception 
	{
		super.delete(className,"issueSlipNo",issueSlip.getIssueNo()+"");
	}

	@Override
	public IssueSlip retreive(String conditionField, String ConditionValue) throws Exception 
	{
		IssueSlip issueSlip=(IssueSlip) super.retreive(className,conditionField, ConditionValue);
		// creating model attributes.
		IssueSlipItemDao issueslipItems =new IssueSlipItemImplementor();
		IssueSlipItem[] allItems = issueslipItems.retreiveArray("slipNo",issueSlip.getAutoissueSlipNo()+"");
		issueSlip.setModelslipitems(allItems);
		issueSlip.setModelBldgName(AppUtilities.getBuildingName(issueSlip.getBldgNo()));
		issueSlip.setmodelcontractorName(AppUtilities.getContractorName(issueSlip.getIdContractor()));
		issueSlip.setModelEmployeeName(AppUtilities.getGenratedByName(issueSlip.getIdEmployee()));
		issueSlip.setModelFlatName(AppUtilities.getFlatName(issueSlip.getFlatNo()));
		issueSlip.setModelprojectName(AppUtilities.getProjectName(issueSlip.getIdProject()));
		return issueSlip;
	}

	@Override
	public IssueSlip[] retreiveArray(String conditionField, String conditionValue) throws Exception 
	{
		IssueSlip[] issueSlips;
		Object[] obj=super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		issueSlips=new IssueSlip[obj.length];
		
		for(int i=0;i<issueSlips.length;i++)
		{
			issueSlips[i]=(IssueSlip) obj[i];
		}
		
		return issueSlips;
	}

	@Override
	public IssueSlip[] retreiveAll() throws Exception 
	{
		IssueSlip[] issueSlips;
		
		Object[] obj=super.retreiveAll(className);
		
		issueSlips=new IssueSlip[obj.length];
		
		for(int i=0;i<issueSlips.length;i++)
		{
			issueSlips[i]=(IssueSlip) obj[i];
		}
		
		return issueSlips;
	}

	@Override
	public int getAutoId() {
		int x=super.getAutoGenratedKey(className, "autoissueSlipNo");
		return x;
	}

}
